//
//  GuidViewController.m
//  SinopecCrm
//
//  Created by QingSong_Hao on 15/4/8.
//  Copyright (c) 2015年 PCITC. All rights reserved.
//

#import "GuidViewController.h"

@interface GuidViewController ()<UIScrollViewDelegate>

@end

@implementation GuidViewController

- (void)viewDidLoad{
    [super viewDidLoad];
    [self createGuideView];
}

#pragma mark - 添加引导页
-(void)createGuideView{
    guideImageArr = @[@"ec_guid_1",@"ec_guid_2",@"ec_guid_3"];
    
    // 滚动视图
    guideScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(ZERO_X,ZERO_Y, SCREEN_WIDTH,SCREEN_HEIGHT)];
    guideScrollView.contentSize = CGSizeMake(SCREEN_WIDTH * guideImageArr.count, SCREEN_HEIGHT);
    guideScrollView.showsHorizontalScrollIndicator = NO;
    guideScrollView.backgroundColor = [self colorHexValue:0xD8DCE1];
    guideScrollView.pagingEnabled = YES;
    guideScrollView.delegate = self;
    [self.view addSubview:guideScrollView];
    
    // 页码图标
    pageControl = [[UIPageControl alloc] init];
    pageControl.frame = CGRectMake(0, SCREEN_HEIGHT -40, SCREEN_WIDTH, 20);
    pageControl.numberOfPages = 3;
    pageControl.currentPage = 0;
    pageControl.pageIndicatorTintColor = [[UIColor blackColor]colorWithAlphaComponent:0.2];
    pageControl.currentPageIndicatorTintColor = [[UIColor blackColor]colorWithAlphaComponent:0.6];
    [self.view addSubview:pageControl];
    
    for(int i = 0;i<guideImageArr.count;i++){
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i*SCREEN_WIDTH, ZERO_Y, SCREEN_WIDTH, SCREEN_HEIGHT)];
        imageView.image = [UIImage imageNamed:guideImageArr[i]];
        imageView.userInteractionEnabled = YES;
        [guideScrollView addSubview:imageView];
        if(i == guideImageArr.count - 1){
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(ZERO_X,ZERO_Y, SCREEN_WIDTH, SCREEN_HEIGHT);
            [button setBackgroundColor:[UIColor clearColor]];
            [button addTarget:self action:@selector(MenuBtn:) forControlEvents:UIControlEventTouchUpInside];
            [imageView addSubview:button];
        }
    }
}

#pragma mark UIScrollView代理方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    int page = scrollView.contentOffset.x / scrollView.frame.size.width;
    pageControl.currentPage = page;
}

#pragma mark 进入程序主界面
-(void)MenuBtn:(id)sender{
    // 调用delegate中赋值的block
    if (_startBlock) {
        _startBlock(YES);
    }
}

@end
